require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '12.0'

target 'Berty' do
  config = use_native_modules!

  use_react_native!(:path => config["reactNativePath"])

  # override OpenSSL-Universal with own openssl static lib
  pod 'OpenSSL-Universal', :path => "./OpenSSL-Universal-Override.podspec"

  # required custom import of permission handler
  permissions_path = '../node_modules/react-native-permissions/ios'
  pod 'Permission-BluetoothPeripheral', :path => "#{permissions_path}/BluetoothPeripheral"
  pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
  pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary"
  pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone"
  pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications"


  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable these next few lines.
  # FIX see: https://github.com/facebook/flipper/issues/2215#issuecomment-829102757
  use_flipper!({ 'Flipper-Folly' => '2.5.3', 'Flipper' => '0.87.0', 'Flipper-RSocket' => '1.3.1' })

  post_install do |installer|
    flipper_post_install(installer)

    # enable only active arch for all pods
    installer.pods_project.build_configurations.each do |config|
      config.build_settings['ONLY_ACTIVE_ARCH'] = 'YES'
    end

    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        # set ios deployment target for all pods
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'

        # replace swift version 4.X -> 5.0
        if config.build_settings.key?('SWIFT_VERSION') && config.build_settings['SWIFT_VERSION'].start_with?('4.')
          config.build_settings['SWIFT_VERSION'] = '5.0'
        end
      end
    end
  end
end
